package dptest;

import java.util.Arrays;

public class t740 {
	public static void main(String[] args) {
		int nums[] = {4,10,10,8,1,4,10,9,7,6};
		Arrays.sort(nums);
		int all[] = new int [nums[nums.length-1]];
		/*for(int i =1; i<=all.length;i++) {
			for(int j = 0; j<nums.length;j++) {
				if(i == nums[j]) {
					all[i-1]++;
				}
			}
		}*/
		for(int allnum : nums) {
			all[allnum]++;
		}
		System.out.print(Arrays.toString(all));
		
		int dp [] = new int [all.length+1];
		dp[0] = all[0]; dp[1] = all[1]*2;
		dp[1] = Math.max(dp[1], dp[0]);
		//dp[2] = Math.max(dp[1], dp[0]);
		for(int i = 2 ; i<all.length;i++) {
			dp[i] = Math.max(dp[i-1], dp[i-2]+all[i]*(i+1));
			
		}
		//return dp[all.length-1];
		System.out.print(dp[all.length-1]);
	}
}
